﻿//Date Helper  
//author: Alexis 2011-06-25
//blog: http://www.cnblogs.com/alexis/

using System.Windows;
using System.Windows.Interactivity;
using System.Windows.Controls;


namespace AccountHelper
{
    /// <summary>
    /// TextBox 聚焦后全选Behavior
    /// </summary>
    public class TextBoxSelectAllOnFocusBehavior:Behavior<TextBox>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            //注册GotFocus 事件
            AssociatedObject.GotFocus += new RoutedEventHandler(AssociatedObject_GotFocus);
        }

        void AssociatedObject_GotFocus(object sender, RoutedEventArgs e)
        {
            AssociatedObject.SelectAll();
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            //卸载GotFocus 事件
            AssociatedObject.GotFocus -= AssociatedObject_GotFocus;
        }
    }
}
